<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>详情页</title>
    <link rel="stylesheet" href="css/detail.css">
    <link rel="stylesheet" href="css/base.css">
    <script src="js/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="top">
    <span>网上借书系统</span>
    <div class="back">
        <a href="index.html">返回首页</a>
    </div>
</div>
<section class="w">
    <div class="mid">
        <div class="book-img">

        </div>
        <div class="mess-box">
            <div class="title">
                <h5 id="name"> 国学经典三部曲《论语》《孙子兵法》《老子》（全本·全注·全译·全解读，黄朴民先生译注解读） </h5>
                <h5 class="introduction">名家译注，精选底本，万字导言，用典注释，精妙解读，选纸考究，封面覆触感膜。黄朴民一次讲透《论语》《老子》《孙子兵法》，带你系统读国学。 </h5>
            </div>
            <div class="autor-info">
                <div class="author">
                    作者：<span id="author"></span>
                </div>
                <div class="press">
                    出版社：<span id="press"></span>
                </div>
                <div class="press-time">
                    出版时间：<span id="press-time"></span>
                </div>
                <div class="type">
                    图书类型：<span id="book-type"></span>
                </div>
            </div>
            <div class="price-info">
                <div class="price">
                    <em>降价通知</em>
                    <div class="down"><i>￥</i><span id="price">255</span></div>
                </div>
            </div>
            <div>剩余数量:<span id="surplus-count"></span></div>
            <div class="borrow">
                <button id="borrow">借书</button>
            </div>
        </div>
    </div>
</section>

</body>
<script>
    $.ajax({
        type: "get",
        url: "http://120.76.130.104:9000/book/getBookMessage",
        data: {
            id: localStorage.getItem("bookId")
        },
        success: function (data, text, xmlHttp) {
            if (xmlHttp.getResponseHeader("Token") == "timeOut" || xmlHttp.getResponseHeader("Token") == "false") {
                localStorage.clear()
                window.location = "login.html"
            } else {
                // let parentWin = window.opener ;
                // // let book = parentWin.document.getElementById("books")
                // book.click(function (){
                //     console.log(11)
                // })
                console.log(data)
                $("#author").html(data.data.author)
                $("#press").html(data.data.press)
                $("#press-time").html(data.data.year)
                $("#price").html(data.data.price)
                $("#surplus-count").html(data.data.count)
                $("#name").html(data.data.name)
                $(".introdution").html(data.data.indroduction)
                $("#book-type").html(data.data.type)
                $(".book-img").append("  <img src=\"img/" + data.data.url + "\" height=\"350\" width=\"350\"/>")
            }
        }
    })


    $("#borrow").click(function () {
        $.ajax({
            type: "get",
            url: "http://120.76.130.104:9000/user/borrowBook",
            data: {
                bookId: localStorage.getItem("bookId")
            },
            headers: {
                Token:localStorage.getItem("Token")
            },
            success:function (data,text,http){
                if (http.getResponseHeader("Token") == "timeOut" || http.getResponseHeader("Token") == "false") {
                    localStorage.clear()
                    window.location = "login.html"
                }else {
                    localStorage.setItem("Token",http.getResponseHeader("Token"))
                    alert(data.msg)
                    if (data.msg == "借书成功") {
                        $("#surplus-count").html($("#surplus-count").text() - 1)
                    }
                }
            }
        })
    })
</script>
</html>